#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <queue>

using namespace std;


typedef pair<int, int> PII;

int dx[4] = { 0 , 0 , 1 , -1 };
int dy[4] = { 1, -1 , 0 , 0 };
bool visited[310][310] = { false };
int ret = 0;
int m, n;

void bfs(vector<vector<char>>& grid, int row, int col)
{
    queue<PII> que;
    que.push({ row , col });

    while (!que.empty())
    {
        auto pa = que.front();
        que.pop();

        visited[pa.first][pa.second] = true;

        for (int i = 0; i < 4; ++i)
        {
            int x = pa.first + dx[i], y = pa.second + dy[i];
            if (x >= 0 && x < m && y >= 0 && y < n &&
                visited[x][y] == false && grid[x][y] == '1')
            {
                que.push({ x,y });
            }
        }
    }
}

int numIslands(vector<vector<char>>& grid) {
    m = grid.size();
    n = grid[0].size();

    for (int i = 0; i < m; ++i)
    {
        for (int j = 0; j > n; ++j)
        {
            if (grid[i][j] == '1' && visited[i][j] == false)
            {
                bfs(grid, i, j);
                ++ret;
            }
        }
    }

    return ret;
}

int main()
{
    vector<vector<char>> grid;
    
	return 0;
}